Problem in sorting attributes

Hi,

I am working on a DXL script to sort enums of attribute type.

The sorting works fine. But the objects are getting wrong values. After sorting the array, I find relative position of an entry in the old enum and try to reload this.

I have attached a code fragment. Could you tell me where the problem is?

Am I usinng the modify() API correctly?

BR, anil.
SystemAdmin - Fri Jul 24 11:12:13 EDT 2009

Re: Problem in sorting attributes
llandale - Fri Jul 24 11:38:37 EDT 2009

Your sortEnum function is modifying the input array. It doesn't matter that you didn't use the ampersand; in fact you cannot use an ampersand & for an input array parameter. You can check this by printing old_enum[] before the sort and then after. You should probably also print your 'map'.

I'd define new_Enum at the same time as the old, and populate its values at the same time, then sort the new.

  • Louie

NitPick: Golly, it was so many years ago when I did this, but: I proved that if you want to sort an array that was not in random order you could save a lot of sort time by having two internal loops. The first swap-loop goes from 1-to-size like you have it, but its then followed by a second swap-loop goes from size-to-1. Since that will always put the lowest value at the bottom and the highest value at the top, you can restrict the loops by [1] 1+Nums-To-(Size-Nums) and [2] (Size-Nums)-to-1+Nums, where Nums was the number of times you've done these loops. Also, the outer loop should be some sort of 'do while(! Done)', setting Done true at the top but setting it false whenever you actually do a swap. With this algorithm, if someone inserted an Enum in the wrong spot (its 'almost' sorted), the sort loop only makes one pass. Woopee.

Forget all that, use the "void sort(string stringArray[])" function.